package com.leapp.sk.ui.activity.archives

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.example.mvp.activity.BaseActivityMVP
import com.example.mvp.binder.BaseDataBinder
import com.leapp.sk.R
import com.leapp.sk.bean.BabyAchivesEntity
import com.leapp.sk.bean.BabyInfoEntity
import com.leapp.sk.binder.BaseBinder
import com.example.util.finallist.BABY_INFO
import com.example.util.finallist.CODE_202
import com.leapp.sk.viewdelegate.archives.BabyArchivesDelegate

/**
 * 宝贝档案
 * @author  chaohaipeng  on 2018/8/7.
 */
class BabyArchivesActivity:BaseActivityMVP<BabyArchivesDelegate>() {
    val mutableListOf = mutableListOf<BabyAchivesEntity>()
    override fun initDate() {

        val babyAchivesEntity = BabyAchivesEntity()
        babyAchivesEntity.type=1
        mutableListOf.add(babyAchivesEntity)
        mutableListOf.add(BabyAchivesEntity())
        viewDelegate.initAdapter(this,mutableListOf)
    }

    override fun bindEvenListener() {
        viewDelegate.setOnClickListener(View.OnClickListener {
            val intent=Intent(this,CompleteBabyInfoActivity::class.java)
            startActivityForResult(intent, CODE_202)
        }, R.id.tv_aba_add)


    }

    override fun getDelegateClass(): Class<BabyArchivesDelegate> {
        return BabyArchivesDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return BaseBinder()
    }

    override fun initView(p0: Bundle?) {
        viewDelegate.setTitle(resources.getString(R.string.string_baby_archives))
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode== CODE_202){
            if (resultCode==CODE_202){
                if (data!=null){
                  val babyData:BabyInfoEntity = data.getSerializableExtra(BABY_INFO) as BabyInfoEntity
                    val babyAchivesEntity = BabyAchivesEntity()
                    babyAchivesEntity.type=1
                    babyAchivesEntity.babyBirth=babyData.babyBirth
                    babyAchivesEntity.babyName=babyData.babyName
                    babyAchivesEntity.babySex=babyData.babySex
                    mutableListOf.add(babyAchivesEntity)
                    viewDelegate.notifyAdapter()
                }


            }
        }


    }


}